/***
 * @Description: eslint 平面配置
 * @Author: smellycat littlecandyi@163.com
 * @Date: 2025-04-12 22:07:03
 * @LastEditors: smellycat littlecandyi@163.com
 * @LastEditTime: 2025-04-12 23:31:00
 */

import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint, { parser as tseslintParser } from 'typescript-eslint'
import unocss from '@unocss/eslint-config/flat'
import pluginRouter from '@tanstack/eslint-plugin-router'
import pluginPrettierRecommendedConfigs from 'eslint-plugin-prettier/recommended'

export default tseslint.config(
	{
		ignores: [
			'*.sh',
			'node_modules',
			'*.md',
			'*.woff',
			'*.ttf',
			'.vscode',
			'.idea',
			'dist',
			'dist-ssr',
			'public',
			'docs',
			'.husky',
			'.local',
			'.github',
			'bin',
			'Dockerfile'
		]
	},
	{
		extends: [
			js.configs.recommended,
			...tseslint.configs.recommended,
			// 使用 unocss 的规则
			unocss,
			...pluginRouter.configs['flat/recommended'],
			// prettier 冲突问题
			pluginPrettierRecommendedConfigs
		],
		files: ['**/*.{ts,tsx}'],
		languageOptions: {
			globals: {
				...globals.browser,
				...globals.es2025
			},
			parser: tseslintParser,
			parserOptions: {
				ecmaVersion: 2025,
				sourceType: 'module'
			}
		},
		plugins: {
			'react-hooks': reactHooks,
			'react-refresh': reactRefresh
		},
		rules: {
			...reactHooks.configs.recommended.rules,
			'react-refresh/only-export-components': ['warn', { allowConstantExport: true }]
		}
	}
)
